﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Profile;
using System.Data;
using Gift.Model.ENUM;
using System.Text;
using Gift.DAL;
using Gift.Model;

namespace WebSite.admin.product
{
    public partial class CardQuery : BaseAdmin
    {
        readonly dalCompany theCompany = new dalCompany();
        readonly DALAdminLogin theAdminLogin = new DALAdminLogin();
        readonly DALCardType theCardType = new DALCardType();


        private void GridViewBind(string Sqlsort)
        {

            string sql = "select distinct C.CardCode,C.CardPrice,(select [name] from tbCardState where Id = C.states) as statesName,0 as userType, '订单号为：' +  OA.OrderCode as code  "
                       + " FROM DB_Card C  "
                       + "  join tbOrderAccount OA on C.Cardid = OA.Cardid "
                       + "  join DB_Order O on OA.OrderCode = O.OrderCode "
                       + " where c.CardCode = '" + this.txtCardCode.Text.Trim() + "' and C.states=2";
            string sql2 = " select distinct C.CardCode,C.CardPrice,(select [name] from tbCardState where Id = C.states) as statesName,1 as userType,MA.MemberId  as id, "
                        + "  '用户名为：' +(select memberlogin from tbMember where MemberId = MA.MemberId) as code "
                       + " FROM DB_Card C "
                       + "  join tbMemberAccount MA on C.Cardid = MA.Cardid "
                       + " where c.CardCode = '" + this.txtCardCode.Text.Trim() + "' and C.states=2";
            string sql3 = " select *,(select [name] from tbCardState where Id = db_card.states) as statesName,2 as userType,'' as code from DB_Card "
                          + " where CardCode = '" + this.txtCardCode.Text.Trim() + "'";

            DataTable table = new DataTable();
            table = SQLAccess.GreatDs(sql).Tables[0];
            if (table.Rows.Count <= 0)
            {
                table = SQLAccess.GreatDs(sql2).Tables[0];
            }
            if (table.Rows.Count <= 0)
            {
                table = SQLAccess.GreatDs(sql3).Tables[0];
            }
            this.Grid1.DataSource = table.DefaultView;
            this.Grid1.DataBind();
          
        }

        protected void Page_Load(object sender, EventArgs e)
        {

            if (!base.IsPostBack)
            {       
                base.ValidateLoginRule(ERule.CardQuery);
                this.GridViewBind("");

            }
        }



        protected void btnSearch_Click(object sender, EventArgs e)
        {
            this.GridViewBind("");
        }

    }
}